<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
    <style type="text/css">
		.header span{
			background:#009680; 
			font-size: 18px;
			margin-left: 10px;
			padding: 5px;

		}
	</style>
</head>
<body style="padding: 10px">
	<div class="header">
		<span>角色管理</span>
		<button style="float: right;margin-right:10px" class="layui-btn layui-btn-xs" onclick="add()">添加</button>
		<hr style="border: solid 1px;">
	</div>
	
	<table class="layui-table">
		<thead>
			<tr>
				<th>ID</th>
				<th>角色名称</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name="data.roles" id="vo"}
			<tr>
				<td>{$vo.gid}</td>
				<td>{$vo.title}</td>
				<td>
					<button class="layui-btn layui-btn-warm layui-btn-xs" onclick="add({$vo.gid})">编辑</button>
					<button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.gid})">删除</button>
				</td>
			</tr>
			{/volist}
		</tbody>
		
	</table>

	<script type="text/javascript">
		layui.use(['layer'],function(){
			layer=layui.layer;
			$=layui.jquery;
		});

		//添加编辑角色
        function add(gid){
		  layer.open({
		  type: 2,
		  title: gid>0?'编辑角色':'添加角色',
		  shade: 0.5,
		  area: ['480px', '500px'],
		  content: '/admins.php/admins/Roles/add?gid='+gid 
		});
		}

		//删除角色
		function del(gid){
			layer.confirm('确定删除？', {
              btn: ['确定','取消'] 
            }, function(){
                $.post('/admins.php/admins/Roles/delete',{'gid':gid},function(res){
                    if(res.code>0){
                        layer.alert('删除失败',{'icon':2});
                   }else{
                    layer.msg('删除成功',{'icon':1});
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                   };

                })
              
            },function(){
            	setTimeout(function(){
            		window.location.reload();

            	},1000)
          }
          , 'json');

		}
	</script>


	
</body>
</html>